<template>
	<view class="question-page">
		<!-- #ifdef APP -->
		<u-navbar title="发布动态" :autoBack="true" :placeholder="true">></u-navbar>
		<!-- #endif -->
		<view class="contentBox">
			<view class="content-box">
				<view class="title">发表内容</view>
				<view style="flex: 1;">
					<u-textarea v-model="dynamicsInfo.content" placeholder="写点什么吧～ 提示:请勿发送色情、涉政等违反国家法律法"
						:clearable="true" border="none" confirmType="done"></u-textarea>
				</view>
			</view>
			<view class="image-box">
				<view class="title">发表图片</view>
				<view style="flex: 1;">
					<uploadImage @uploadSuccess='uploadSuccess' name="image" :maxCount='9' width="180rpx"
						height="180rpx"></uploadImage>
				</view>
			</view>
			<view class="setting-box">
				<view class="setting-item">
					<view class="item-left">
						<u-icon name="map-fill" size="16"></u-icon>
						<view style="margin-left: 10rpx;">{{dynamicsInfo.city||'获取中'}}</view>
					</view>
					<view class="item-right">
						<view style="margin-right: 20rpx;">显示位置</view>
						<u-switch v-model="dynamicsInfo.is_city" active-color="#f169f6"></u-switch>
					</view>
				</view>
			</view>
			<view class="button-group">
				<view class="button1" @click="$u.throttle(addForumInfo,2000)">发布</view>
			</view>
		</view>
		<view style="height: 20rpx;"></view>
	</view>
</template>

<script>
	import uploadImage from '@/components/UploadImage.vue';
	export default {
		data() {
			return {
				dynamicsInfo: {
					content: "",
					images: "",
					city_id: "",
					city: "",
					is_city: false
				}
			}
		},
		components: {
			uploadImage: uploadImage
		},
		onLoad(options) {
			let searchData = uni.getStorageSync('searchData') || {}
			if (searchData.city_id) {
				this.dynamicsInfo.city_id = searchData.city_id
				this.dynamicsInfo.city = searchData.city_name
			}
		},
		methods: {
			addForumInfo() {
				if (!this.dynamicsInfo.images) {
					return this.$Toast('请上传动态图片')
				}
				this.$Api['user'].addForumInfo({
					...this.dynamicsInfo,
					is_city: this.dynamicsInfo.is_city ? '1' : '0'
				}).then(res => {
					this.$Tips({
						title: '发布成功'
					}, {
						tab: 3,
						url: '1'
					})
				})
			},
			uploadSuccess(e) {
				this.dynamicsInfo.images = e.fileList
			}
		}
	}
</script>

<style lang="less" scoped>
	.question-page {
		width: 100%;
		min-height: 100vh;
		background-color: #f7f8fa;
		position: relative;

		.contentBox {
			min-height: 80vh;
			margin: 20rpx;
			padding: 38rpx 40rpx 38rpx;
			box-shadow: 0rpx 4rpx 32rpx 0rpx #FFF0FD;
			border-radius: 32rpx;
			background: linear-gradient(180deg, #FFDAF5 0%, #FFFFFF 5%);

			.content-box,
			.image-box {
				margin-top: 40rpx;

				.title {
					font-size: 28rpx;
					margin: 42rpx 0 20rpx;
				}

				::v-deep .u-textarea {
					background-color: #f7f7f7;
					border-radius: 16rpx;
				}
			}

			.setting-box {
				position: relative;
				margin-top: 40rpx;
				font-size: 28rpx;
				color: #323334;

				.setting-item {
					display: flex;
					align-items: center;
					justify-content: space-between;

					.item-left,
					.item-right {
						display: flex;
						align-items: center;
					}
				}
			}

			.button-group {
				.button1 {
					margin: 160rpx auto 0;
					width: 628rpx;
					height: 88rpx;
					font-weight: bold;
					font-size: 30rpx;
					color: #FFFFFF;
					text-align: center;
					line-height: 88rpx;
					background: linear-gradient(135deg, #FE93BF 0%, #A27AFF 100%);
					box-shadow: 0rpx 4rpx 10rpx 0rpx #FDC4FF;
					border-radius: 44rpx;
				}
			}
		}
	}
</style>